<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('列表')" />
</head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								统计时间：<input id="dateType" class="dateType" type="text" name="dateType"/>
							</li>

							<!--<li>
								渠道名称：
								<select  id="channelName" name="channelName"></select>
							</li>-->

<!--							<li>-->
<!--								商户名称：<input type="text" name="merchantName"/>-->
<!--							</li>-->

							<li>
								支付方式：
								<select  id="payKindName" name="payKindName"></select>
							</li>

							<li>
								统计类型：
								<select type="text" name="statisticsType">
									<option value="1">天</option>
									<option value="2">小时</option>
								</select>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="merchantStatistics:statisticsPay:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('statistics:statisticsPay:edit')}]];
        var removeFlag = [[${@permission.hasPermi('statistics:statisticsPay:remove')}]];
        var prefix = ctx + "merchantStatistics/statisticsPay";


        var $form = $("#formId");
        // 初始化默认时间值
        var time = new Date();
        var y = time.getFullYear();
        var m = time.getMonth() + 1;
        var d = time.getDate();
        function add0(m) {
            return m < 10 ? '0' + m : m
        }
        var nowTime = y + '-' + add0(m);
        $form.find("input[name='dateType']").val(nowTime);



        /*渠道下拉框*/
        $.post(prefix + "/channelList", {'name':''},function (response) {
            if (response.code == 0) {
                var data = response.rows;
                var option = "<option value=''>" + "" + "</option>";
                for (var i = 0; i < data.length; i++) {
                    option += "<option value='"+ data[i].name +"'>" +data[i].name + "</option>"
                }
                $form.find("select[name='channelName']").html("").append(option);
            }else {
                $.modal.alertError("初始化信息异常");
            }
        });



        /*支付类型标识下拉框 */
        $.post(prefix + "/paykindList", {'name':''},function (response) {
            var data = response.rows;
            var option = "<option value=''>" + "全部" + "</option>";
            for (var i = 0; i < data.length; i++) {3
                option += "<option value='"+ data[i].name +"'>" + data[i].name + "</option>"
            }
            $form.find("select[name='payKindName']").html("").append(option);
        });


        /*初始化查询参数*/
        function queryParams(params){
            var search = $.table.queryParams(params);
            search.dateType = $("#dateType").val();
            search.statisticsType = $("#formId").find("select[name='statisticsType']").val();
            return search;
        }



        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "支付统计",
		        showExport: true,
                queryParams: queryParams,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id',
					title : '标识',
					visible: false
				},
                {
                    field : 'dateType',
                    title : '统计时间',
                },
				{
					field : 'expectTimes',
					title : '预期支付数'
				},
				{
					field : 'expectFee',
					title : '预期支付额(元)',
					sortable: true,
                    formatter: function (value, row, index) {
						if(value != null){
							var data = new Decimal(value).div(new Decimal(100.00));
							return data;
						}
                    }
				},
				{
					field : 'expectMchFee',
					title : '预期商户入账(元)',
					sortable: true,
                    formatter: function (value, row, index) {
                        var data = new Decimal(value).div(new Decimal(100.00));
                        return data;
                    }
				},
				{
					field : 'realTimes',
					title : '实际支付数',
					sortable: true
				},
				{
					field : 'realFee',
					title : '实际支付额(元)',
					sortable: true,
                    formatter: function (value, row, index) {
						if(value != null){
							var data = new Decimal(value).div(new Decimal(100.00));
							return data;
						}
                    }
				},
				{
					field : 'realMchFee',
					title : '实际商户入账(元)',
					sortable: true,
                    formatter: function (value, row, index) {
						if(value != null){
							var data = new Decimal(value).div(new Decimal(100.00));
							return data;
						}
                    }
				},
                //  {
                //      field : 'channelId',
                //      title : '渠道标识',
                //      visible: false
                //  },
                //  {
                //      field : 'channelName',
                //      title : '渠道名称',
                //  },
                //  {
                //      field : 'channelCode',
                //      title : '渠道编码',
                //  },
                // {
                // 	field : 'merchantId',
                // 	title : '商户标识',
                // 	sortable: true,
                //     visible: false
                // },
                // {
                // 	field : 'merchantName',
                // 	title : '商户名称',
                // 	sortable: true
                // },
                // {
                //     field : 'merchantCode',
                //     title : '商户编码',
                // },
                {
                    field : 'payKindId',
                    title : '支付方式标识',
                    visible: false
                },
                {
                    field : 'payKindName',
                    title : '支付方式名称',
                },
                {
                    field : 'payKindCode',
                    title : '支付方式编码',
                },
                {
                    field : 'statisticsType',
                    title : '统计类型',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return "天";
                        }
                        if (value === 2) {
                            return "小时";
                        }
                    }
                },
                {
                    field : 'statisticsTime',
                    title : '插入时间',
                },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });


        /*时间控件*/
        // laydate input_time 时间控件绑定
        if ($(".dateType").length > 0) {
            layui.use('laydate', function () {
                var com = layui.laydate;
                $(".dateType").each(function (index, item) {
                    var time = $(item);
                    // 控制控件外观
                    var type = time.attr("data-type") || 'month';
                    // 控制回显格式
                    var format = time.attr("data-format") || 'yyyy-MM';
                    // 控制日期控件按钮
                    var buttons = time.attr("data-btn") || 'clear|now|confirm', newBtnArr = [];
                    // 日期控件选择完成后回调处理
                    var callback = time.attr("data-callback") || {};
                    if (buttons) {
                        if (buttons.indexOf("|") > 0) {
                            var btnArr = buttons.split("|"), btnLen = btnArr.length;
                            for (var j = 0; j < btnLen; j++) {
                                if ("clear" === btnArr[j] || "now" === btnArr[j] || "confirm" === btnArr[j]) {
                                    newBtnArr.push(btnArr[j]);
                                }
                            }
                        } else {
                            if ("clear" === buttons || "now" === buttons || "confirm" === buttons) {
                                newBtnArr.push(buttons);
                            }
                        }
                    } else {
                        newBtnArr = ['clear', 'now', 'confirm'];
                    }
                    com.render({
                        elem: item,
                        theme: 'molv',
                        trigger: 'click',
                        type: type,
                        format: format,
                        btns: newBtnArr,
                        done: function (value, data) {
                            if (typeof window[callback] != 'undefined'
                                && window[callback] instanceof Function) {
                                window[callback](value, data);
                            }
                        }
                    });
                });
            });
        }

    </script>
</body>
</html>